Fix editor state leaking when switching automations, scripts, or scenes - #53826
Conversation
Recreate the page when the item id in the route changes so YAML mode, undo history, and scene live state cannot carry over to the next item.
Path-shape matching remounted nested config routers, Lovelace, and developer tools. Recreate only where edit/show routes opt in.
A remounted editor starts in review; disconnect only needs to drop the subscription, not undo device changes from live mode.
|
This means that when saving an automation for the first time (from new -> id) also recreates the editor? |
| oldTail !== newTail | ||
| ) { | ||
| delete this._cache[newPage]; | ||
| this._createPanel(routerOptions, newPage, routeOptions); |
There was a problem hiding this comment.
I think this should not just create the panel? It skips the loading screen right now, and a dynamically imported panel would fail?
There was a problem hiding this comment.
Changing it to go through load
| routeOptions.itemId && | ||
| oldTail !== newTail | ||
| ) { | ||
| delete this._cache[newPage]; |
There was a problem hiding this comment.
It will never be in the cache anyway right?
Yes, we will get a repaint. I think that's ok |
|
For the scene editor, probably unrelated to this PR, but shouldn't leaving the page also call |
Will create a follow up PR for this |
Clear the current page instead of calling _createPanel directly so load and the loading screen still run. Drop the redundant cache delete.
Nested submit/cancel schedules a nextRender callback that ran after Vitest tore down HTMLElement, failing CI with an unhandled rejection.
…es (#53826) * Fix editor state leaking when switching automations, scripts, or scenes Recreate the page when the item id in the route changes so YAML mode, undo history, and scene live state cannot carry over to the next item. * Declare itemId on editor routes instead of guessing from the path Path-shape matching remounted nested config routers, Lovelace, and developer tools. Recreate only where edit/show routes opt in. * Do not restore scene live states when the editor is torn down A remounted editor starts in review; disconnect only needs to drop the subscription, not undo device changes from live mode. * Use the normal create path when remounting itemId pages Clear the current page instead of calling _createPanel directly so load and the loading screen still run. Drop the redundant cache delete. * Fix dialog-form tests leaking focus restore after jsdom teardown Nested submit/cancel schedules a nextRender callback that ran after Vitest tore down HTMLElement, failing CI with an unhandled rejection.
Proposed change
Opening another automation, script, or scene while already editing one reused the same editor element, so YAML mode, undo history, pending registry edits, and scene live control could carry over. Saving could then write the previous item's content onto the newly opened item.
HassRouterPagenow recreates the page when the remaining path is a single item id and that id changes. Those pages are also not cached. Nested routers (for exampleha-config-automation) stay in place so cached dashboards survive. In-flight editor loads are ignored after disconnect, and a scene editor in live mode restores stored states when it is torn down.Saving a new item remounts as well, so YAML mode is not kept after the first save.
Type of change
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed:
To help with the load of incoming pull requests: